#include "mainscene.h"
#include "./ui_mainscene.h"
#include<QPainter>
#include"mypushbutton.h"
#include<QTimer>

MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{

    ui->setupUi(this);



    //点击退出键实现退出
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });

    //设置宽高
    this->setFixedSize(320,588);

    //设置标题
    this->setWindowTitle("翻金币主场景");
    //设置图标
    this->setWindowIcon(QPixmap(":/new/prefix1/res/Coin0001.png"));

    MyPushButton * startBtn=new MyPushButton(":/new/prefix1/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);
    //创建第二个场景
    this->chooseScene=new ChooseLevelScene;

    connect(startBtn,&MyPushButton::clicked,[=](){
        //qDebug()<<"进入到选关场景";
        //实现一点按钮，按钮上下跳动的动画
        startBtn->zoom1();
        startBtn->zoom2();

        //进行延时，不然看不到上面的按钮跳跃的动画
        QTimer::singleShot(500,this,[=](){
            //显示第二个场景
            this->chooseScene->show();
            //隐藏当前场景
            this->hide();
        });

    });

    //监听第二场景的返回信号按钮
    connect(this->chooseScene,&ChooseLevelScene::chooseSceneBck,[=](){
        this->show();
        this->chooseScene->hide();
    });
}

//绘图事件
void MainScene::paintEvent(QPaintEvent*){
    //创建画家对象
    QPainter painter(this);
    //创建Qpixmap对象
    QPixmap pix;
    pix.load(":/new/prefix1/res/PlayLevelSceneBg.png");

    //绘制背景
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    pix.load(":/new/prefix1/res/Title.png");

    //pix=pix.scaled((pix.width()*0.5,pix.height()*0.5));
    // 缩放操作
    QSize newSize(pix.width() * 0.5, pix.height() * 0.5); // Calculate the new size
    pix = pix.scaled(newSize); // Scale the pixmap

    painter.drawPixmap(10,30,pix);
 }

MainScene::~MainScene()
{
    delete ui;
}
